package work_master;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author wuguojian
 * @description
 * @date 2022/7/4 下午10:05
 **/
public class MasterWorkerTest {

    //简单任务
    static class SimpleTask extends Task<Integer> {
        @Override
        protected Integer doExecute() {
            System.out.println("task " + getId() + " is done ");
            return getId();
        }
    }

    public static void main(String[] args) {
        Master<SimpleTask, Integer> master = new Master<>(4);
        ExecutorService masterService = Executors.newFixedThreadPool(2);
        masterService.execute(() -> master.submit(new SimpleTask()));
        ExecutorService workerService = Executors.newFixedThreadPool(4);
        workerService.execute(() -> master.printResult());
    }

}
